package servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.AnnounceDao;
import dao.RestoreDao;
import dao.UserDao;
import dao.impl.AnnounceDaoImpl;
import dao.impl.RestoreDaoImpl;
import dao.impl.UserDaoImpl;
import model.Announces;
import model.User;

/**
 * Servlet implementation class ReadServlet
 */
@WebServlet("/ReadServlet")
public class ReadServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ReadServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		String annId = request.getParameter("ID");
		AnnounceDao ad = new AnnounceDaoImpl();
		UserDao ud = new UserDaoImpl();
		RestoreDao rd = new RestoreDaoImpl();
		try {
			Announces ann = ad.queryAnntByAnnID(Integer.parseInt(annId));
			request.setAttribute("AnnAccountInfo", ann);
			request.setAttribute("UserInfo", ud.getUserById(ann.getUserID()));
			request.setAttribute("userList", rd.getUserListByAnnID(ann.getAnnID()));
			request.setAttribute("restoreList", rd.getRestoreListByAnnID(ann.getAnnID()));
			request.getRequestDispatcher("pages/comment.jsp").forward(request, response);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
